<?php


require 'database.php';

$issue=$_GET["i"];
$key=$_GET["k"];
// /api/order.php?issue=3418889&treeid=2&pid=4&money=550
$_f__=file_get_contents("demo.json");
$_f__=json_decode($_f__,1);

if(!$key){
    $key=6;
}

$p=$_GET["p"];

if(strstr($p,",")){
    $p=explode(",",$p);
    $c= $key / count($p);
    for ($x = 0; $x < count($p); $x++) {
        for ($i = 1; $i <= $c; $i++) {
            $url=$_f__["site"]."/api/order.php?issue=".$issue."&treeid=".$i."&pid=".$p[$x]."&money=1";
            file_get_contents($url);
        }
    }
}else{

    for ($i = 1; $i <= $key; $i++) {
        $url=$_f__["site"]."/api/order.php?issue=".$issue."&treeid=".$i."&pid=".$p."&money=1";
        file_get_contents($url);
    }
}

// for ($i = 1; $i < 11; $i++) {
//     $url=$_f__["site"]."/api/order.php?issue=33235861&treeid=".$i."&pid=3&money=1";
//     file_get_contents($url);
// }



$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => $_f__["site"]."/api/auto.php",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET"
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}



